package model.domain;


import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "productbacklog", catalog = "scrum")
public class Product implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer productID;
	private Priority priority;
	private Project project;
        private Sprint sprint;
	private String description;
	private String comments;
	private List<Task> sprintbacklogs;

	public Product() {
	}

	public Product(Priority priority, Project project,
			String cdescription) {
		this.priority = priority;
		this.project = project;
		this.description = cdescription;
	}

	public Product(Priority priority, Project project, Sprint sprint,
			String cdescription, String ccomments, List<Task> sprintbacklogs) {
		this.priority = priority;
		this.project = project;
                this.sprint = sprint;
		this.description = cdescription;
		this.comments = ccomments;
		this.sprintbacklogs = sprintbacklogs;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "nPBID", unique = true, nullable = false)
	public Integer getProductID() {
		return this.productID;
	}

	public void setProductID(Integer npbid) {
		this.productID = npbid;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nPriorityID", nullable = false)
	public Priority getPriority() {
		return this.priority;
	}

	public void setPriority(Priority priority) {
		this.priority = priority;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nProjectID", nullable = false)
	public Project getProject() {
		return this.project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nSprintID")
	public Sprint getSprint() {
		return this.sprint;
	}

	public void setSprint(Sprint sprint) {
		this.sprint = sprint;
	}

	@Column(name = "cDescription", nullable = false, length = 50)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String cdescription) {
		this.description = cdescription;
	}

	@Column(name = "cComments", length = 500)
	public String getComments() {
		return this.comments;
	}

	public void setComments(String ccomments) {
		this.comments = ccomments;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "productbacklog")
	public List<Task> getSprintbacklogs() {
            return this.sprintbacklogs;
	}

	public void setSprintbacklogs(List<Task> sprintbacklogs) {
		this.sprintbacklogs = sprintbacklogs;
	}

            @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }
        final Product other = (Product) obj;
        if(this.productID == null){
            if(other.getProductID() != null){
                return false;
            }
        } else if(!this.productID.equals(other.getProductID())){
            return false;
        }
        return true;

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.productID != null ? this.productID.hashCode() : 0);
        hash = 47 * hash + (this.description != null ? this.description.hashCode() : 0);
        return hash;
    }

}
